import sys
import time
import ptc

fileName=sys.argv[6]
file=open(fileName, 'r')
data=file.read()
print '[File-Client] Using file: %s' % fileName
fileLen=len(data)
print '[File-Client] Data in file has: %s bytes' % fileLen

clientIp=sys.argv[1]
clientPort=int(sys.argv[2])
clientWindow=int(sys.argv[3])
startTime = time.time()
print '[File-Client] Starting client at %s:%s and window: %s' % (clientIp, clientPort, clientWindow)
client=ptc.PTCClient(clientIp, clientPort, clientWindow)
serverIp=sys.argv[4]
serverPort=int(sys.argv[5])
print '[File-Client] Connecting to server at %s:%s' % (serverIp, serverPort)
client.connect(serverIp, serverPort)
print '[File-Client] Sending file length to server'
client.send(str(fileLen)+'|')
print '[File-Client] Sending file data to server'
client.send(data)
print '[File-Client] Closing client'
client.close()
print "[File-Client] Waiting for close"
client.wait_for_close()
endTime = time.time()
print '[File-Client] Done in %s ms' % (endTime - startTime)
#client.write_tab_data()

with open(sys.argv[7], 'w') as f:
  f.write('%s;%s;%s;%s\n' % (fileLen, clientWindow, (endTime - startTime), client.get_retrans_count()))
